/**
 * 功能描述 列表
 */

define(function (require, exports, module){
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	var store =require("store");
	var activeUser = store.get("user");
	var planfile = require("../store/planfile");
	var customerEvents = require("../handler/customer__Events");
	
	var instance = {
		initComponent:function (params,widget){
			var grid = new Grid({
				parentNode:".J-grid",
				model:{
					url:"api/customer/query",
					params : function(){
	        			var subnav = widget.get("subnav");
	        			return {
	        				"dataSourceIn" : subnav.getValue("dataSource"),
	        				"saleConsultant": activeUser.pkUser,
	        				fetchProperties:planfile.fetchProperties
	        			}
	        		},
					columns:[{
						name: "personalInfo.name",
						label: "姓名"
					},{
						name: "personalInfo.sex.value",
						label: "性别",
					},{
						name: "personalInfo.idNumber",
						label: "证件号码",
					},{
						name:"personalInfo.birthday",
						label:"出生日期",
						format:"date",
						formatparams:{
							mode:"YYYY-MM-DD"
						}
					},{
						name:"age",
						label:"年龄",
						format: function(value,row){
							if(row.personalInfo.birthday == null){
								return 0;
							}else{
								var year = parseInt(moment().format("YYYY-MM-DD").substr(0,4)); 
								var birthday_year = parseInt(moment(row.personalInfo.birthday).format("YYYY-MM-DD").substr(0,4));
								return year - birthday_year;
							}
						}
					},{
						name:"personalInfo.mobilePhone",
						label:"联系电话"
					},{
						name:"address",
						label:"地址",
						format: function(value,row){
							return (row.personalInfo.houseRegister == null ? "" : row.personalInfo.houseRegister.fullName)
							+(row.personalInfo.address == null ? "" : row.personalInfo.address);
						}
					},{
						name:"dataSource",
						label:"客户类型",
						format: function(value,row){
							if(row.dataSource.key == "NoMember"){
								return "体验客户";
							}else if(row.dataSource.key == "Visit"){
								return "意向客户";
							}else{
								return "";
							}
							
						}
					},{
						name:"show",
						label:"操作",
						format:"button",
						formatparams:[{
							id:"edit",
							icon:"icon-edit",
							text:"查看",
							handler:function(index,data,rowEle){
	    						customerEvents.grid.handleShowClick(widget, data);
							}
						}]
					}]
				}
			});
			widget.set("grid",grid);
		}
	};
	module.exports = instance;
});
